package com.lishuang.domain.json;

import com.lishuang.base.Enums.DeviceStatus;
import java.io.Serializable;
import java.util.Random;

/**
 * @author LiShuang
 * @version 1.0.0
 * @date 2022/11/5 15:43
 */

/**
 * int deviceId：设备编号，整数值。如果添加设备时，没有指定，则随机生成编号。
 *      注意：该值唯一确定一个设备身份，在数据库中作为主键
 * String deviceName：设备名称。如果没有填写，那么会使用设备种类+序号来代替。
 * String deviceCategory：设备种类，必填
 * String uuid：任务号。该值是设备连接到网关后，随机分配的任务号。
 *      注意：下一次设备连入网关时，这个id可能会发生变化！
 * DeviceStatus deviceStatus：设备状态
 * int priority：设备优先级，1~10
 * TODO:<reserved>以下为预留字段</reserved>
 * String location：设备地址
 * String IP：设备IP
 * String MAC：设备MAC
 * String GroupID：设备分组
 */
public class Device implements Serializable,Comparable<Device>{
    private int deviceId;
    private String deviceName;
    private String deviceCategory;
    private String uuid;
    private DeviceStatus deviceStatus;
    private int devicePriority;
    private static int series=1;
    //默认构造函数
    public Device(){}

    public Device(int deviceId, String deviceCategory) {
        this.deviceId = deviceId;
        this.deviceCategory = deviceCategory;
        this.devicePriority =5;
        this.deviceName=this.deviceCategory;
        this.uuid=null;
        this.deviceStatus=DeviceStatus.offline;
    }

    public Device(boolean isExample){
        Random random = new Random();
        deviceId= random.nextInt(100000)+1;
        deviceName="Example"+series++;
        deviceCategory = "Example";
        devicePriority =random.nextInt(10);
        uuid=null;
        this.deviceStatus=DeviceStatus.offline;
    }

    public Device(Device device){
        deviceId=device.deviceId;
        deviceName=device.getDeviceName();
        deviceStatus=device.getDeviceStatus();
        deviceCategory=device.getDeviceCategory();
        uuid=device.getUuid();
        devicePriority =device.getDevicePriority();
    }
    public Device(int deviceId, String deviceName, String deviceCategory, String uuid, DeviceStatus deviceStatus, int devicePriority) {
        this.deviceId = deviceId;
        this.deviceName = deviceName;
        this.deviceCategory = deviceCategory;
        this.uuid = uuid;
        this.deviceStatus = deviceStatus;
        this.devicePriority = devicePriority;
    }


    public int getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(int deviceId) {
        this.deviceId = deviceId;
    }

    public String getDeviceName() {
        return deviceName;
    }

    public void setDeviceName(String deviceName) {
        this.deviceName = deviceName;
    }

    public String getDeviceCategory() {
        return deviceCategory;
    }

    public void setDeviceCategory(String deviceCategory) {
        this.deviceCategory = deviceCategory;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public DeviceStatus getDeviceStatus() {
        return deviceStatus;
    }

    public void setDeviceStatus(DeviceStatus deviceStatus) {
        this.deviceStatus = deviceStatus;
    }

    public int getDevicePriority() {
        return devicePriority;
    }

    public void setDevicePriority(int devicePriority) {
        this.devicePriority = devicePriority;
    }

    //用于修改设备接口
    public void modify(Device device){
        deviceId=device.deviceId;
        deviceName=device.getDeviceName();
        //NOTICE:设备类型不支持修改！
        //deviceCategory=device.getDeviceCategory();
        uuid=device.getUuid();
        devicePriority =device.getDevicePriority();
    }
    @Override
    public int compareTo(Device device) {
        // 优先级越小越优先
        return devicePriority-device.devicePriority;
    }
    public void setInterrupted(){}
}
